﻿@model Sheng.WeixinConstruction.Management.Shell.Models.PictureVoteItemDetailViewModel

@{
    ViewBag.Title = "PictureVoteItemDetail";
    Layout = "~/Views/Shared/_LayoutBlank.cshtml";
}

<script type="text/javascript">

    var _id = getQueryString("id");
    var _lock;

    $(document).ready(function ()
    {
        var status = @((int)Model.PictureVoteItem.ApproveStatus);
        //Waiting
        if(status == 0){
            $("#btnApprove").show();
            $("#btnReject").show();
            $("#btnLock").hide();
        }
            //Approved
        else if(status == 1){
            $("#btnApprove").hide();
            $("#btnReject").hide();
            $("#btnLock").show();
        }
            //Rejected
        else{
            $("#btnApprove").hide();
            $("#btnReject").hide();
            $("#btnLock").hide();
        }

        _lock = @Model.PictureVoteItem.Lock.ToString().ToLower();
        if(_lock){
            $("#btnLock").val("解 锁");
        }else{
            $("#btnLock").val("锁 定");
        }

    });

    function approve()
    {
        var msg = "是否确认审核通过？"

        var confirmLayerIndex = layer.confirm(msg, {
            btn: ['确认', '取消'], //按钮
            shade: [0.4, '#393D49'],
            title: false,
            closeBtn: false,
            shift: _layerShift
        }, function ()
        {
            layer.close(confirmLayerIndex);

            var loadLayerIndex = layer.load(0, {
                shade: [0.2, '#fff']
            });

            var args = new Object();
            args.CampaignId = "@Model.PictureVoteItem.CampaignId";
        args.ItemId = _id;

        @if (Model.PictureVoteItem.Member.HasValue)
        {
            <text>
            args.MemberId = "@Model.PictureVoteItem.Member.Value";
            </text>
        }

            $.ajax({
                url: "/Api/Campaign/PictureVoteItemApprove",
                type: "POST",
                dataType: "json",
                data: JSON.stringify(args),
                success: function (data, status, jqXHR)
                {
                    layer.close(loadLayerIndex);
                    if (data.Success)
                    {
                        layerAlert("审核通过。",function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.loadDataOnPageAndCloseLayer(index);
                        });

                    } else
                    {
                        layerAlert(data.Message);
                    }
                },
                error: function (xmlHttpRequest)
                {
                    layer.close(loadLayerIndex);
                    alert("Error: " + xmlHttpRequest.status);
                }
            });
        });

        
    }

    function reject(message)
    {
        var args = new Object();
        args.CampaignId = "@Model.PictureVoteItem.CampaignId";
        args.ItemId = _id;
        args.Message = message;

        @if (Model.PictureVoteItem.Member.HasValue)
        {
            <text>
        args.MemberId = "@Model.PictureVoteItem.Member.Value";
            </text>
        }

        var loadLayerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        $.ajax({
            url: "/Api/Campaign/PictureVoteItemRejected",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(args),
            success: function (data, status, jqXHR)
            {
                layer.close(loadLayerIndex);
                if (data.Success)
                {
                    layerAlert("已拒绝。",function(){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.loadDataOnPageAndCloseLayer(index);
                    });

                } else
                {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest)
            {
                layer.close(loadLayerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

    function lock(){

        var confirmMsg = "是否确认锁定该项目？"
        if(_lock){
            confirmMsg = "是否确认解除该项目的锁定？";
        }

        var confirmLayerIndex = layer.confirm(confirmMsg, {
            btn: ['确认', '取消'], //按钮
            shade: [0.4, '#393D49'],
            title: false,
            closeBtn: false,
            shift: _layerShift
        }, function ()
        {
            layer.close(confirmLayerIndex);

            var url = "/Api/Campaign/PictureVoteItemLock?id=" + _id;
            var msg = "该项目已被锁定，不再允许投票。";

            if(_lock){
                url = "/Api/Campaign/PictureVoteItemUnLock?id=" + _id;
                msg = "该项目已解除锁定。";
            }

            var loadLayerIndex = layer.load(0, {
                shade: [0.2, '#fff']
            });

            $.ajax({
                url: url,
                type: "POST",
                dataType: "json",
                success: function (data, status, jqXHR)
                {
                    layer.close(loadLayerIndex);
                    if (data.Success)
                    {
                        layerAlert(msg,function(){
                            window.location.reload();
                        });

                    } else
                    {
                        layerAlert(data.Message);
                    }
                },
                error: function (xmlHttpRequest)
                {
                    layer.close(loadLayerIndex);
                    alert("Error: " + xmlHttpRequest.status);
                }
            });
        });

        
    }

    function cancel()
    {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    }

    function refresh(){
        location.reload();
    }

    function removeData()
    {
        if (_id == undefined || _id == "")
        {
            return;
        }

        var msg = "是否确认删除该投票项目？"

        var confirmLayerIndex = layer.confirm(msg, {
            btn: ['确认', '取消'], //按钮
            shade: [0.4, '#393D49'],
            title: false,
            closeBtn: false,
            shift: _layerShift
        }, function ()
        {
            layer.close(confirmLayerIndex);

            var loadLayerIndex = layer.load(0, {
                shade: [0.2, '#fff']
            });

            $.ajax({
                url: "/Api/Campaign/RemovePictureVoteItem?id=" + _id,
                type: "POST",
                dataType: "json",
                success: function (data, status, jqXHR)
                {
                    layer.close(loadLayerIndex);
                    if (data.Success)
                    {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.loadDataOnPageAndCloseLayer(index);

                    } else
                    {
                        layerAlert(data.Message);
                    }
                },
                error: function (xmlHttpRequest)
                {
                    layer.close(loadLayerIndex);
                    alert("Error: " + xmlHttpRequest.status);
                }
            });
        });
    }

</script>

<div style="margin-left: 20px; margin-right: 20px; margin-top: 20px;">
    <span id="spanTitle" class="font_black_24">详情</span>
</div>

<div style="background-color: #ccc; margin-left: 20px; margin-right: 20px; margin-top: 10px; height: 1px;">
</div>

<div style="position: absolute; overflow: auto; margin-top: 25px; left: 30px; right: 30px; bottom: 60px; top: 50px;">

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td width="250" valign="top">
                <img src="@Model.PictureVoteItem.Url" style="max-width:220px;" />
            </td>
            <td valign="top">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="110" height="36">标题：</td>
                        <td>@Model.PictureVoteItem.Title</td>
                    </tr>
                    <tr>
                        <td height="36">说明：</td>
                        <td>@Model.PictureVoteItem.Description</td>
                    </tr>
                    <tr>
                        <td height="36">上传时间：</td>
                        <td>@Model.PictureVoteItem.UploadTime</td>
                    </tr>
                    <tr>
                        <td height="36">当前票数：</td>
                        <td>@Model.PictureVoteItem.VoteQuantity</td>
                    </tr>
                    <tr>
                        <td height="36">审核状态：</td>
                        <td>@Model.PictureVoteItem.ApproveStatusString</td>
                    </tr>
                    @if (Model.PictureVoteItem.ApproveStatus == Sheng.WeixinConstruction.Infrastructure.EnumCampaignPictureVoteItemApproveStatus.Rejected)
                    {
                        <tr>
                            <td height="36">拒绝原因：</td>
                            <td>@Model.PictureVoteItem.RejectedMessage</td>
                        </tr>
                    }
                </table>

            </td>
        </tr>
    </table>


</div>

<div style="background-color: #ccc; position: absolute; bottom: 55px; left: 20px; right: 20px; height: 1px;">
</div>

<div style="position: absolute; bottom: 15px; left: 20px; right: 20px;">

    <div style="float: left;">
        <input name="btnApprove" type="button" class="btn_blue" id="btnApprove" value="审 核" style="width: 140px;" onclick="approve()" />
        <input name="btnReject" type="button" class="btn_blue" id="btnReject" value="拒 绝" onclick="__showInputForm(reject,'拒绝原因',100,true);" />
        <input name="btnLock" type="button" class="btn_blue" id="btnLock" value="锁 定" onclick="lock()" />
    </div>

    <div style="float: right">
        <input name="btnRemove" type="button" class="btn_red" id="btnRemove" value="删 除" onclick="removeData()" />
        <input name="btnCancel" type="button" class="btn_blue" id="btnCancel" value="关 闭" onclick="cancel()" />
    </div>

    <div style="clear: both">
    </div>
</div>
@Helpers.InputForm()